//
//  JHCollectViewController.m
//  Liberty Voice
//
//  Created by dlios on 15-5-13.
//  Copyright (c) 2015年 ClearLove. All rights reserved.
//

#import "JHCollectViewController.h"
#import "JHAblumViewController.h"
#import "JHDataBaseManager.h"

@interface JHCollectViewController ()<UITableViewDataSource,UITableViewDelegate>
@property(nonatomic,retain)NSMutableArray *arr;
@property(nonatomic,retain)UITableView *t;
@property(nonatomic,retain)JHDataBaseManager *hdManager;
@end

@implementation JHCollectViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.t = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
    _t.delegate = self;
    _t.dataSource = self;

    [self.view addSubview:_t];
    [_t release];
    self.hdManager = [JHDataBaseManager shareInstance];
    [_hdManager openDB];
    self.arr = [_hdManager selectInfo];

//    self.arr = [NSMutableArray array];
//    self.arr = [aaa selectInfo];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    /**
     *  tableView
     *
     *  @return 点击
     */
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    JHAblumViewController *aaaaa = [[JHAblumViewController alloc] init];
    aaaaa.albumId = [_arr[indexPath.row]albumId];
    [self.navigationController pushViewController:aaaaa animated:YES];
    
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // 行数
    return _arr.count;
}
//- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
//{
//    return _arr.count;
//}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    // 重用池
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"f"];
    if (!cell) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"f"]autorelease];
    }
    cell.textLabel.text = [_arr[indexPath.row]title];
    return cell;
    
}
/**
 *  tableView
 *
 *  @param editing  编辑
 *  @param animated 方法
 */
- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
    [super setEditing:editing animated:animated];
    [_t setEditing:editing animated:animated];
}
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return UITableViewCellEditingStyleDelete;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    [_hdManager deleteInfoWithNum:[[[_arr[indexPath.row]albumId]description]integerValue]];
    [_arr removeObjectAtIndex:indexPath.row];
    NSArray *a = @[indexPath];
    [_t deleteRowsAtIndexPaths:a withRowAnimation:UITableViewRowAnimationLeft];
    [_t reloadData];
}
- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return @"删除";
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
